using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using Utility;
using BUS;
public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        tbSanPhamCollection  spCollection = tbSanPhamBUS.GetAll();
        tbLoaiSPCollection loaispCollection = tbLoaiSPBUS.GetAll();
        Repeater1.DataSource = spCollection;
        Repeater1.DataBind();
        Repeater2.DataSource = loaispCollection;
        Repeater2.DataBind();
    }



    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
            e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbSanPham sanpham = (tbSanPham)e.Item.DataItem;
            HyperLink hyp_tensp = (HyperLink)e.Item.FindControl("hyp_tensp");
            Image img_HinhAnh = (Image)e.Item.FindControl("img_hinhanh");
            Literal lit_giaban = (Literal)e.Item.FindControl("lit_giaban");
            Literal lit_giatrithuc = (Literal)e.Item.FindControl("lit_giatrithuc");
            Literal lit_songuoimua = (Literal)e.Item.FindControl("lit_songuoimua");
            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");
            HyperLink hyp_xem = (HyperLink)e.Item.FindControl("hyp_xem");
            hyp_tensp.Text = sanpham.TenSP;
            lit_giaban.Text = sanpham.GiaBan.ToString();
            lit_giatrithuc.Text = sanpham.GiaTriThuc.ToString();
            lit_songuoimua.Text = sanpham.SLDaBan.ToString();
            hf_id.Value = sanpham.IdSanPham.ToString();
            hyp_xem.NavigateUrl = "Detail.aspx?id=" + sanpham.IdSanPham.ToString();

            int Id = 0;
            int MaHA = tbHinhAnhBUS.FirstImage(int.Parse(sanpham.IdSanPham.ToString()), Id);
            if (MaHA > 0)
            {
                tbHinhAnh hinhAnh = tbHinhAnhBUS.GetById(MaHA);
                img_HinhAnh.ImageUrl = "~/Photos/" + hinhAnh.TenHinh.ToString();
            }
            else
            {
                img_HinhAnh.ImageUrl = "~/Photos/no_images.jpg";
            }
        }
    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
            e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbLoaiSP loaiSP=(tbLoaiSP )e.Item .DataItem ;
            HyperLink hyp_loaisp = (HyperLink)e.Item.FindControl("hyp_loaisp");
            hyp_loaisp.Text = loaiSP.TenLoai;
        }
    }
}
